package com.gxa.meiye.admin.platform.controller;

import com.gxa.meiye.admin.platform.pojo.vo.*;
import com.gxa.meiye.admin.platform.service.AdvertisementService;
import com.gxa.meiye.core.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api
@RestController
@RequestMapping("/advert")
public class AdvertisementController {

    @Autowired
    private AdvertisementService advertisementService;

    @ApiOperation("内容管理列表")
    @GetMapping("/advertList")
    public Map advertList(){
        List<AdvertVo> advertVos = advertisementService.selectAdvertList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(advertVos);
        return jsonResult.getMap();
    }

    @ApiOperation("轮播图列表")
    @GetMapping("/slideshowList")
    public Map slideshowList(){
        List<SlideshowVo> slideshowVos = advertisementService.selectSlideshowList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(slideshowVos);
        return jsonResult.getMap();
    }

    @ApiOperation("新增轮播图")
    @PostMapping("/add")
    public Map add(@RequestBody AdvertisementVo advertisementVo){
        advertisementService.addSlideshow(advertisementVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("修改轮播图状态")
    @PostMapping("/updateStatus")
    public Map updateStatus(@RequestBody UpdateStatusVo statusVo){
        advertisementService.updateStatus(statusVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }

    @ApiOperation("条件查询")
    @PostMapping("/select")
    public Map select(@RequestBody SelectVo selectVo){
        List<AdvertisementVo> advertisementVos =null;
        if(selectVo.getStatus()!=null) {
            advertisementVos = advertisementService.selectSlideshows(selectVo);
        }else {
            advertisementVos = advertisementService.selectSlides(selectVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(advertisementVos);
        return jsonResult.getMap();
    }

    @ApiOperation("进入修改")
    @PostMapping("/preUpdate")
    public Map preUpdate(Integer id){
        AdvertisementVo advertisementVo = advertisementService.selectById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(advertisementVo);
        return jsonResult.getMap();
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public Map update(@RequestBody AdvertisementVo advertisementVo){
        advertisementService.updateAdvertisement(advertisementVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("删除广告")
    @PostMapping("/del")
    public Map del(Integer id){
        advertisementService.del(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }
}
